/* ------------------------------------------------------------------------
Cookieマネージャー
	Copyright (c) 2009, Matsumoto.JS All rights reserved.
	
【使用方法】（なるべく<head>タグ内にて）
<script src="js/prototype.js" type="text/javascript"></script>
<script src="js/cookie.js" type="text/javascript"></script>

【パラメータの説明】
オブジェクトリテラルで指定
	path: パス、Cookie送出対象を狭める場合（default:"/"）
	expire: 有効期間（default:0=セッション限り）
 ------------------------------------------------------------------------ */
CookieManager = Class.create();
CookieManager.prototype = {

initialize: function(option) {
	this.props = { path: '/', expire: 0 };
	if(option) for(var key in option) this.props[key] = option[key];
},

getCookie: function(cookieName) {
	var cookies = document.cookie.split('; ');
	var cookieVal = null;
	for (var i = 0; i < cookies.length; i++) {
		var names = cookies[i].split('=');
		if (names[0] == cookieName) {
			cookieVal = names[1];
			break;
		}
	}
	return cookieVal;
},

setCookie: function(cookieName, cookieVal) {
	var expires = '';
	if (this.props.expire > 0) {
		var date = new Date();
		date.setTime(date.getTime() + (this.props.expire * 24*60*60*1000));
		expires = '; expires=' + date.toGMTString();
	}
	document.cookie = cookieName + '=' + cookieVal + expires + '; path=' + this.props.path;
},

removeCookie: function(cookieName) {
	document.cookie = cookieName + '=; path=' + this.props.path;
}
}//prototype